package com.wing.cabinet.model.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

/**
 * 售刀柜上货(上货主表无展示)/领取明细
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("cab_cell_inventory_inout_detail")
public class CellInventoryInoutDetail extends BaseEntity<CellInventoryInoutDetail> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Type implements IEnum<Integer> {

        /**
        * 上货
        */
        in(1,"上货"),
        /**
        * 领取
        */
        out(2,"领取"),

        unload(3,"下货"),

        outByCabSpace(4,"领取");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static Type jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Type item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 上货/领取id
     */
    private Long inoutId;

    /**
     * 柜子id
     */
    private Long cabId;

    /**
     * sku id
     */
    private Long skuId;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 企业id
     */
    private Long companyId;

    /**
     * 货道id
     */
    private Long spaceId;

    /**
     * 操作类型
     */
    private Type type;

    /**
    * 操作类型描述
    */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * sku code
     */
    private String skuCode;

    /**
     * 柜子编码
     */
    private String cabCode;


    /**
     * 货道
     */
    private String spaceCode;

    /**
     * 当前库存
     */
    private Integer quantityCurrent;

    /**
     * 变动后库存
     */
    private Integer quantityAfter;

    /**
     * 是否同步成功
     */
    private Integer isSyns;

    @TableField(exist = false)
    private String inoutUniqCode;

    /**
     * 企业编码
     */
    private String enterpriseCode;

    /**
     * 同步时间
     */
    @JsonFormat(timezone = "GMT+8" , pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime synsTime;


    private BigDecimal price;

    private BigDecimal total;

    /**
     * 主柜编码
     */
    private String mainCabCode;

    private Long storageInventoryInoutDetailId;

    private Integer quantitySingleCabCurrent;

    private Integer quantitySingleCabAfter;

    private Integer quantityCabCurrent;

    private Integer quantityCabAfter;
    /**
     * 渠道编号
     */
    private String channelCode;

    private Integer settingTime;


    private Integer remainingTime;



    /**
     * 寿命单位  1：小时/ 2：次数
     */
    private LifeUnit lifeUnit;

    /**
     * 1：分钟/ 2：个数
     */
    public enum LifeUnit implements IEnum<Integer> {

        /**
         * 分钟
         */
        minute(1,"分钟"),
        /**
         * 个数
         */
        number(2,"个数");

        private int code;
        private String desc;

        LifeUnit(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static LifeUnit jsonCreator(String name) {
            if (org.apache.commons.lang.StringUtils.isNotBlank(name)) {
                for (LifeUnit item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }


    }

    private Integer quantityPack;

    private Integer quantityPackUnit;

    private Long packId;



    private String packName;

    private String unitName;


    private Integer quantityPackCurrent;

    private Integer quantityPackAfter;


    private Integer quantityPackSingleCabCurrent;

    private Integer quantityPackSingleCabAfter;


    private Integer quantityPackCabCurrent;

    private Integer quantityPackCabAfter;
}

